﻿<%@ WebHandler Language="C#" Class="AjaxPage" %>
using System.Collections.Generic; 
using System.IO; 
using System.Runtime.Serialization.Json; 
using System.Web.Services;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
public partial class AjaxPage : System.Web.UI.Page
{
    [WebMethod]
    public static string GetNvrSn()
    {
        Dictionary<string, string> data = new Dictionary<string, string>();
        Database db = DatabaseFactory.CreateDatabase();
        var cmd = db.GetStoredProcCommand("proc_DeviceInfo_t_autocomplete");
        var reader = db.ExecuteReader(cmd);
        int i = 0;
        while (reader.Read())
        {
            i++;
            string str = reader.GetString(0);
            data.Add(str, i.ToString());
        }
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(data.GetType());
        using (MemoryStream ms = new MemoryStream())
        {
            serializer.WriteObject(ms, data);
            return System.Text.Encoding.UTF8.GetString(ms.ToArray());
        }
    }

    [WebMethod]
    public static string GetUser()
    {
        Dictionary<string, string> data = new Dictionary<string, string>();
        Database db = DatabaseFactory.CreateDatabase();
        var cmd = db.GetStoredProcCommand("proc_userinfo_autocomplete");
        var reader = db.ExecuteReader(cmd);
        int i = 0;
        while (reader.Read())
        {
            i++;
            string str = reader.GetString(0);
            data.Add(str, i.ToString());
        }
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(data.GetType());
        using (MemoryStream ms = new MemoryStream())
        {
            serializer.WriteObject(ms, data);
            return System.Text.Encoding.UTF8.GetString(ms.ToArray());
        }
    }
}
    
